package com.item 
{
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author wen
	 */
	public class BirdsView 
	{
		private var _con:MovieClip = null;
		
		private  var _hasAddList:Array = null;
		
		private const NUMS:int = 10;
		
		private var _currentBird:Bird = null;
		
		private var _birdsList:Array = null;
		
		private var _birdsNum:int = 0;
		
		public function BirdsView() 
		{
			
		}
		
		public function init(con:MovieClip):void
		{
			_con = con;
			_hasAddList = new Array();
			_birdsList = new Array();
			
			initBirds();
		}
		
		private function initBirds():void 
		{
			for (var i:int = 0; i < NUMS; i++ )
			{
				var o:Object = new Object();
				o.id = i ;
				o.y = 200 - 2400 * (i + 1) * 2;
				
				_birdsList.push(o);
			}
		}
		
		public function initItem():void
		{
			addClildBird();
		}
		
		public function addClildBird():void 
		{
			if (_birdsNum < _birdsList.length)
			{
				var tmpMc:birdMc = new birdMc();
				var tmpBird:Bird = new Bird(tmpMc);
				var o:Object = _birdsList[_birdsNum];
				
				_hasAddList.push(tmpBird);
				
				_con.addChild(tmpMc);
				
				tmpMc.y = o.y;
				tmpBird.id = o.id;
				_birdsNum++;
			}
		}
		
		public function get hasAddList():Array 
		{
			return _hasAddList;
		}
		
		public function get currentBird():Object 
		{
			return _currentBird;
		}
		
		public function set currentBird(value:Object):void 
		{
			_currentBird = _hasAddList[value.num] as Bird;
			
			_currentBird.stepOn();
			
			_hasAddList.splice(value.num, 1);
			
			addClildBird();
		}
		
		public function deleteBird(num:int):void
		{
			(_hasAddList[num] as Bird).clearView();
			_hasAddList.splice(num, 1);
			
			addClildBird();
		}
		
		
		public function clear():void
		{
			for (var i:int = 0; i < _hasAddList.length; i++ )
			{
				(_hasAddList[i] as Bird).clearView();
			}
			
			_hasAddList = new Array();
			_currentBird = null;
			_birdsNum = 0;
		}
	}
	
}